
console.log("-------希尔排序demo---------");
var arr = [10, 8, 4, 2, 6];
console.log(arr.join(" ") + "\n");
function SortHandle(arr) {
  let len = arr.length;
  let gap = len / 2 | 0
  while (gap >= 1) {
    for (let outer = gap; outer < len; outer++) {
      const temp = arr[outer]
      let inner = outer
      while (inner - gap >= 0 && arr[inner - gap] > temp) {
        arr[inner] = arr[inner - gap]
        inner -= gap
      }
      arr[inner] = temp
    }
    gap = gap / 2 | 0
    //打印排序
    console.log(arr.join(" ") + "\n");
  }
  return arr;
}
SortHandle(arr);






